class MyThread extends Thread {
    private String name;

    public MyThread(String name) {
        this.name = name;
    }

    public void run() {
        System.out.println(name + " 正在执行...");
        try {
            Thread.sleep(1000); // 模拟任务执行
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(name + " 执行完毕!");
    }
}

public class demo1 {
    public static void main(String[] args) throws InterruptedException {
        MyThread thread1 = new MyThread("线程1");
        MyThread thread2 = new MyThread("线程2");
        MyThread thread3 = new MyThread("线程3");

        thread1.start();
        thread2.start();
        thread3.start();

        // 主线程等待所有子线程执行完毕
        thread1.join();
        thread2.join();
        thread3.join();

        System.out.println("所有线程都已执行完毕，主线程继续执行...");
    }
}
